package com.bdbit.ChargingStation.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import org.springframework.data.annotation.Id;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Date;
@Entity
@Table(name = "charging_order")
@Data
public class ChargingOrder {
    // 订单状态常量
    public static final int STATUS_UNPAID = 0;           // 未支付
    public static final int STATUS_PAID_WAITING = 1;     // 已支付待充电  
    public static final int STATUS_CHARGING = 2;         // 充电中
    public static final int STATUS_COMPLETED = 3;        // 充电完成
    public static final int STATUS_REFUNDED = 4;         // 已退款
    public static final int STATUS_TIMEOUT = 5;          // 超时
    public static final int STATUS_CANCELLED = 6;        // 已取消
    
    @javax.persistence.Id
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;  // 这是主键ID，应该保持为Long类型

    @Column(name = "user_id")
    private String userId;

    @Column(name = "order_year_month")
    private String orderYearMonth;

    private Integer status;

    @Column(name = "pile_id")
    private String pileId;

    @Column(name = "region_code")
    private String regionCode;

    @Column(name = "ele_code")
    private String eleCode;

    @Column(name = "charging_kwh")
    private BigDecimal chargingKwh;

    @Column(name = "unit_price")
    private BigDecimal unitPrice;

    @Column(name = "total_amount")
    private BigDecimal totalAmount;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "start_time")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date startTime;

    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(name = "end_time")
    private Date endTime;

    @Column(name = "reported_duration")
    private Integer reportedDuration;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "device_start_time")
    private Date deviceStartTime;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "device_end_time")
    private Date deviceEndTime;

    @Column(name = "prepay_amount")
    private BigDecimal prepayAmount;

    @Column(name = "payment_method")
    private String paymentMethod;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "payment_time")
    private Date paymentTime;

    @Column(name = "refund_amount")
    private BigDecimal refundAmount;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "refund_time")
    private Date refundTime;

    @Temporal(TemporalType.DATE)
    @Column(name = "create_date")
    @CreationTimestamp
    private Date createDate;

    @Temporal(TemporalType.DATE)
    @Column(name = "update_date")
    @UpdateTimestamp
    private Date updateDate;


    @Column(name = "is_deleted")
    private Integer isDeleted;

    @Column(name = "pay_type")
    private String payType;

    @Column(name = "payment_form")
    private String paymentForm;

    @Column(name = "charging_minutes")
    private Integer chargingMinutes;

    @Column(name = "order_id")
    private String orderId;  // 这是订单号，应该是String类型

    // 必须添加默认构造函数
    public ChargingOrder() {
    }
    // 删除错误的@Transient getChargingMinutes方法，使用简单的getter
    public Integer getChargingMinutes() {
        return chargingMinutes;
    }

    public void setChargingMinutes(Integer chargingMinutes) {
        this.chargingMinutes = chargingMinutes;
    }
    // 删除错误的 getOrderId() 方法，让 Lombok 自动生成正确的方法
    // 或者修正为：
    public String getOrderId() {
        return orderId;  // 返回 orderId 字段而不是 id 字段
    }
}